package com.prototype.view {
	import flash.display.DisplayObject;
	import flash.events.Event;
	/**
	 * ...
	 * @author Santiago.J.Elizalde
	 */
	public class DogView extends MCRunningDog {
		
		private var _forceY:Number=0;
		private var _forceX:Number=0;
		
		private var gravity:Number = 0.4;
		private var friction:Number = 0.4;
		
		public var jumping:Boolean;
		public var attacking:Boolean;
		
		public function DogView() {
			super();
		}
		
		public function run():void {
			gotoAndPlay("run");
		}
		public function jump():void {
			if (!jumping) {
				gotoAndPlay("jumpUp");
				jumping = true;
				_forceY = -8;
			}
		}
		public function attack():void {
			if (!attacking) {
				gotoAndPlay("attack");
				attacking = true;
			}
		}
		public function lookRight():void {
			scaleX = -1;
		}
		public function lookLeft():void {
			scaleX = 1;
		}
		public function collidesWith(obj:DisplayObject):Boolean {
			if (!parent || !obj.parent) {
				return false;
			}
			return getRect(this.parent).intersects(obj.getRect(obj.parent));
		}
		
		public function update():void {
			
			if (attacking && currentFrame == totalFrames) {
				attacking = false;
				gotoAndPlay("run");
			} else {
				if (_forceY < 0 && currentLabel != "jumpUp") {
					gotoAndPlay("jumpUp");
				} else if (_forceY > 0 && currentLabel != "jumpDown") {
					gotoAndPlay("jumpDown");
				} else if(currentLabel != "run") {
					gotoAndPlay("run");
				}
			}
			
			this.y += _forceY;
			this.x += _forceX;
		}
		
		public function get forceY():Number {
			return _forceY;
		}
		public function set forceY(value:Number):void {
			_forceY = value;
		}
		
		public function get forceX():Number {
			return _forceX;
		}
		public function set forceX(value:Number):void {
			_forceX = value;
		}
	}
}